package org.zju.demo.service.impl;

import org.zju.demo.model.OrderUser;
import org.zju.demo.service.intf.OrderUserIntf;
import org.zju.demo.utils.HibernateUtil;

import java.util.List;

/**
 * Created by admin on 2015/8/27.
 */
public class OrderUserImpl implements OrderUserIntf{

    public List<OrderUser> findByOrderId(int orderId) {
        String hql = "from OrderUser where orderId=?";
        String[] parameters = {Integer.toString(orderId)};
        List<OrderUser> list = HibernateUtil.executeQuery(hql, parameters);
        return list;
    }

    public List<OrderUser> findByUserId(int userId) {
        String hql = "from OrderUser where userId=?";
        String[] parameters = {Integer.toString(userId)};
        List<OrderUser> list = HibernateUtil.executeQuery(hql, parameters);
        return list;
    }

    public List<OrderUser> findByUserIdLastNRecords(int userId, int n) {
        String hql = "from OrderUser where userId=?";
        String[] parameters = {Integer.toString(userId)};
        List<OrderUser> list = HibernateUtil.executeQueryFinalNRecords(hql, parameters, n);
        return list;
    }

    public void save(OrderUser orderUser) {
        HibernateUtil.saveIfNotExists(orderUser);
    }
}
